"""
练习1
"""

# with open('text.txt','r',encoding = 'utf-8')as f:
#      # print(f.read())
#     # 将文件内容读取出来      read ()   readlines()  readline
#     result = f.read()
#     print(result)
#     # 用字符串count方法，传入参数
#     print(result.count('python'))

# """
# 练习2
# """
# with open('text.txt','r',encoding = 'utf-8') as f:
#     res = f.read()
#     print(res)
#     # 行数
#     str_list = res.split('\n')
#     # 统计行数
#     count=0
#     for i in str_list:
#         count += 1
#     print(f"总行数为：{count}")


with open('text.txt','w',encoding='utf-8')as f:
    f.write(f'2023-10-01 晴 \n 今天学习了Python的文件操作\n' )
print('日记输入完成！')


with open('text.txt','a',encoding='utf-8')as f:
    f.write(f'{input('用户请输入今天的日期:')}')
    f.write(f'{input('用户请输入今天的天气:')}\n')
    f.write(f'{input('用户请输入今天的心情总结:')}\n')
print('今日日记已完成！')